package com.dingpeikeji.quickdeer.modules.rentproduct.web;

import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.modules.office.entity.SysOffice;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.RentproductDebt;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.RentproductDebtService;

/**
 * 用户欠款
 *
 */
@Controller
@RequestMapping(value = "${adminPath}/rentproduct/debt")
public class RentproductDebtController {
	
	@Autowired
	private RentproductDebtService rentproductDebtService;

	/**
	 * 欠款列表
	 */
	@RequiresPermissions("rentproduct:debt:view")
	@RequestMapping("list")
	public String list(RentproductDebt debt, HttpServletRequest request, HttpServletResponse response, Model model) {
		if(debt.getCredityears()==null){ // 如果年份为空，则默认当前年
			debt.setCredityears(Calendar.getInstance().get(Calendar.YEAR));
		}
		if(debt.getOffice()==null){
			debt.setOffice(new SysOffice());
		}
		Page<RentproductDebt> page = rentproductDebtService.findPage(new Page<RentproductDebt>(request, response), debt); 
		model.addAttribute("page", page);
		model.addAttribute("debt", debt);
		return "modules/rentproduct/debtList";
	}
}
